package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.utils.BeanUtils;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.po.InteractionQuestion;
import com.tianji.learning.domain.po.LearningLesson;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.query.QuestionPageQuery;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author gml
 * @since 2024-06-25
 */
@Api(tags = "互动提问的问题表接口")
@RestController
@RequestMapping("/questions")
@RequiredArgsConstructor
public class InteractionQuestionController {
    private final IInteractionQuestionService interactionQuestionService;

    @PostMapping
    @ApiOperation("新增互动提问的问题")
    public void saveQuestion(@RequestBody QuestionFormDTO questionDTO) {
        interactionQuestionService.saveQuestion(questionDTO);
    }

    @GetMapping("page")
    @ApiOperation("分页查询互动提问的问题")
    public PageDTO<QuestionVO> getQuestionPage(QuestionPageQuery query) {
        return interactionQuestionService.getQuestionPage(query);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询互动提问的问题")
    public InteractionQuestion getQuestionById(@PathVariable("id") Long id) {
        return interactionQuestionService.getQuestionById(id);
    }

    @PutMapping("/{id}")
    @ApiOperation("修改互动提问的问题")
    public void updateQuestion(
            @ApiParam(value = "id", example = "1") @PathVariable("id") Long id,
            @ApiParam(value = "questionDTO", required = true) @RequestBody InteractionQuestion interactionQuestion) {
        interactionQuestionService.update().eq("id", id).update(interactionQuestion);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除互动提问的问题")
    public void deleteQuestion(@ApiParam(value = "id", example = "1") @PathVariable("id") Long id) {
        interactionQuestionService.removeById(id);
    }
}
